﻿using System;
using System.Data;
using BLL;
using Microsoft.Office.Core;
using Model;
using NCRE学生考试端V1._0.PPT操作题类;
using ppt = Microsoft.Office.Interop.PowerPoint;


namespace NCRE学生考试端V1._0
{
    /// <summary>
    /// 根据考题类型判分
    /// </summary>
    public class PptJudege
    {
        readonly ppt.Application pa1 = new ppt.ApplicationClass();
        readonly ppt.Presentation pp1;
        public PptJudege()
        {
            pp1 = pa1.Presentations.Open(string.Format("D:\\{0}\\计算机一级考生文件\\{1}卷\\Pptkt\\PPT{2}.pptx", MyInfo.MystudentID(), MyInfo.MyPaperType(), MyInfo.MyPaperType()), MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);
        }
        /// <summary>
        /// 以题型判分，记录考生作答信息
        /// </summary>
        /// <param name="pptinfo"></param>
        public void Judge(PptQuestionEntity pptinfo)
        {
            //根据学号查询该学生要考的试题和试卷类型，
            PptQuestionEntityBLL pptquestionbll = new PptQuestionEntityBLL();
            DataTable dt = pptquestionbll.LoadPptByFlag(pptinfo);
            //将考生答案传递给studentrecord实体
            PptQuestionRecordEntity studentrecord = new PptQuestionRecordEntity();
            studentrecord.StudentID = FrmLogin.studentID;
            studentrecord.TimeStamp = MyInfo.TimeTamp();
            studentrecord.ExamAnswer = "未找到对象";
            studentrecord.QuestionID = 1;
            studentrecord.Fration = "0";

            //获取PPT元素位置坐标
            int[] m = new PptJudgeHelper().PlaceFlag(pptinfo.PlaceFlag);
            //覆盖考生答案
            if (dt.Rows.Count != 0 && pp1.Slides.Count >= 1)
            {
                studentrecord.QuestionID = Convert.ToDouble(dt.Rows[0]["QuestionID"]);
                try
                {
                    switch (pptinfo.QuestionFlag)
                    {
                        #region 根据类型判分
                        case "幻灯片版式":
                            if (dt.Rows[0]["QuestionContent"].ToString() == "空白版式，")
                            {
                                studentrecord.ExamAnswer = pp1.Slides[m[0]].Shapes.Count.ToString();
                            }
                            else
                            {
                                studentrecord.ExamAnswer = pp1.Slides[m[0]].Shapes[m[1]].Height.ToString();
                            }
                            break;
                        case "删除占位符":
                            studentrecord.ExamAnswer = pp1.Slides[m[0]].Shapes.Count.ToString();
                            break;
                        case "超链接":
                            if (pptinfo.PaperType == "G")
                            {
                                studentrecord.ExamAnswer = pp1.Slides[m[0]].Hyperlinks[m[1]].SubAddress.Substring(0, 6);
                            }
                            else
                            {
                                studentrecord.ExamAnswer = pp1.Slides[m[0]].Hyperlinks[m[1]].Address.ToString();
                            }
                            break;
                        case "删除幻灯片":
                        case "插入幻灯片":
                        case "添加幻灯片":
                            studentrecord.ExamAnswer = pp1.Slides.Count.ToString();
                            break;
                        case "移动幻灯片":
                            studentrecord.ExamAnswer = pp1.Slides[m[0]].Name;
                            break;
                        case "背景颜色":
                            studentrecord.ExamAnswer = pp1.Slides[m[0]].Background.Fill.PresetGradientType.ToString();
                            break;
                        case "声音":
                            studentrecord.ExamAnswer = pp1.Slides[m[0]].SlideShowTransition.SoundEffect.Name;
                            break;
                        case "文本框":
                            studentrecord.ExamAnswer = pp1.Slides[m[0]].Shapes[m[1]].Width.ToString();
                            break;
                        case "艺术字样式":
                            studentrecord.ExamAnswer = pp1.Slides[m[0]].Shapes[m[1]].TextFrame.TextRange.Font.Color.RGB.ToString();
                            break;
                        case "艺术字形状":
                            studentrecord.ExamAnswer = pp1.Slides[m[0]].Shapes[m[1]].TextEffect.PresetShape.ToString(); ;
                            break;
                        case "插入字":
                        case "文本框插入字":
                        case "艺术字文本":
                        case "艺术字字体":
                            studentrecord.ExamAnswer = pp1.Slides[m[0]].Shapes[m[1]].TextFrame2.TextRange.Text.ToString();
                            break;
                        case "切换效果":
                            studentrecord.ExamAnswer = pp1.Slides[m[0]].SlideShowTransition.EntryEffect.ToString();
                            break;
                        case "切换时间":
                            studentrecord.ExamAnswer = pp1.Slides[m[0]].SlideShowTransition.AdvanceOnClick.ToString();
                            break;
                        case "动画时间":
                            studentrecord.ExamAnswer = pp1.Slides[m[0]].Shapes[m[1]].AnimationSettings.AdvanceTime.ToString();
                            break;
                        case "动画效果":
                        case "图片动画效果":
                            studentrecord.ExamAnswer = pp1.Slides[m[0]].Shapes[m[1]].AnimationSettings.EntryEffect.ToString();
                            break;
                        case "插入图片":
                            studentrecord.ExamAnswer = pp1.Slides[m[0]].Shapes[m[1]].Height.ToString();
                            break;
                        case "图片大小":
                            if (pptinfo.PaperType == "D")
                            {
                                studentrecord.ExamAnswer = pp1.Slides[m[0]].Shapes[m[1]].Height.ToString();
                            }
                            else
                            {
                                studentrecord.ExamAnswer = pp1.Slides[m[0]].Shapes[m[1]].Width.ToString();
                            }
                            break;
                        case "自动换片时间":
                            studentrecord.ExamAnswer = pp1.Slides[1].SlideShowTransition.AdvanceTime.ToString();
                            break;
                        case "字体颜色":
                            ppt.ColorFormat mycolor = pp1.Slides[m[0]].Shapes[m[1]].TextFrame.TextRange.Font.Color;
                            studentrecord.ExamAnswer = mycolor.RGB.ToString();
                            break;
                        case "字体":
                            studentrecord.ExamAnswer = pp1.Slides[m[0]].Shapes[m[1]].TextFrame.TextRange.Font.Name.ToString();
                            break;
                        case "字号":
                        case "标题字号":
                            studentrecord.ExamAnswer = pp1.Slides[m[0]].Shapes[m[1]].TextFrame.TextRange.Font.Size.ToString();
                            break;
                        case "加粗":
                            studentrecord.ExamAnswer = pp1.Slides[m[0]].Shapes[m[1]].TextFrame2.TextRange.Font.Bold.ToString();
                            break;
                        case "主题":
                            studentrecord.ExamAnswer = pp1.Slides[m[0]].Design.Name.ToString();
                            break;
                        case "标题字体":
                            studentrecord.ExamAnswer = pp1.Slides[m[0]].Shapes[m[1]].TextFrame2.TextRange.Font.Name.ToString();
                            break;
                            #endregion
                    }
                }
                catch
                {
                    studentrecord.ExamAnswer = "空";
                }
                if (studentrecord.ExamAnswer == dt.Rows[0]["RightAnswer"].ToString())
                {
                    studentrecord.Fration = dt.Rows[0]["Fration"].ToString();
                }
            }
            PptLoadinfo.list.Add(studentrecord);
        }
    }
}
